﻿using System.Windows.Forms;
using System.Drawing;
using System;
using NeuralNetworks.Networks;
using NeuralNetworks.Neurons;

namespace NeuralNetworks
{
    class ConnectionPanel : Panel
    {
        private Label nameLabel;
        private TextBox weightBox;

        //public ActivationNetwork ActivationNetwork;
        private int layer;
        private int input;
        private int neuronNumber;

        public int Layer { get { return layer; } }
        public int Input { get { return input; } }
        public int NeuronNumber { get { return neuronNumber; } }

        public double Weight 
        { 
            get 
            {
                double w = 999999999.0;
                try
                {
                    w = Double.Parse(weightBox.Text);
                    return w;
                }
                catch (System.FormatException)
                {
                    MessageBox.Show("Błędny format jednej z wag (warstwa = " + layer +
                        ", wejście = " + input + "). \nPopraw i spróbuj ponownie.");
                    return 99999.0;
                }
                catch (Exception exception)
                {
                    MessageBox.Show("Błąd wprowadzonej wagi.(warstwa = " + layer +
                        ", wejście = " + input + ").\n\n" + exception.Message);
                    return 99999.0;
                }
            } 
        }

        public ConnectionPanel(int layer, int prevNeuron, int currNeuron, Neuron neuron) : base()
        {
            this.layer = layer;
            this.input = prevNeuron;
            this.neuronNumber = currNeuron;

            nameLabel = new Label();
            nameLabel.Size = new Size(35, 15);
            nameLabel.Location = new Point(0, 0);
            // format: C [neuron poprzedniej warstwy] -> [neuron aktualnej warstwy]
            nameLabel.Text = "C" + (prevNeuron + 1).ToString() + "->" + (currNeuron + 1).ToString();
            nameLabel.BackColor = Color.Gray;

            weightBox = new TextBox();
            weightBox.Size = new Size(35, 20);
            weightBox.Location = new Point(0, 15);
            weightBox.Text = (neuron.Inputs[prevNeuron] as Connection).Weight.ToString();

            this.Controls.Add(nameLabel);
            this.Controls.Add(weightBox);
            this.Size = new Size(35, 35);
        }

    }
}
